﻿#include "SplitResultWidget.h"
#include <QMouseEvent>
#include <QPainter>

SplitResultWidget::SplitResultWidget(QWidget *parent)
	: QWidget(parent)
{
	
}

SplitResultWidget::~SplitResultWidget()
{
}

void SplitResultWidget::paintEvent(QPaintEvent *event)
{
	QPainter painter(this);
	int x_offset = 12; 
	int y_offset = 12;
	int space = 8;

	QRgb backColor = qRgb(21, 29, 202);
	QRgb barColor = qRgb(73, 196, 165);
	QRgb redColor = qRgb(255, 0, 0);
	QRgb nameColor = qRgb(173, 232, 148);
	painter.fillRect(rect(), backColor);

	int w = (rect().width()  - 2*x_offset - space*7) / 8;
	int h = (rect().height() - 2*y_offset - space*3) / 4;

	double x_gap = (rect().width()  - 2*x_offset - w * 8) / 7.0;
	double y_gap = (rect().height() - 2*y_offset - h * 4) / 3.0;

	QRect rc(0, 0, w, h);
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			rc.moveTo(x_offset + (w + x_gap) * j, y_offset + (h + y_gap) * i);

			int item_idx = i * 8 + j;
			if (m_channels.indexOf(item_idx) >= 0)
				painter.fillRect(rc, redColor);
			else
				painter.fillRect(rc, barColor);
		}
	}
}

void SplitResultWidget::setChannels(QVector<int> channels)
{
	m_channels = channels;
	update();
}